home *** CD-ROM | disk | FTP | other *** search
- /***************** Listing 1 *************************
-
- Nearest Neighbour Interpolation
-
- double nearest(image, x, y)
- float image[2][2], x, y;
-
- image: pointer to the four values of grid i.e.
- a 2 x 2 array ( image[2][2] )
- x : sample coordinate
- y : line coordinate
-
- p
- |----->
- image(0,0) image(0,1)
- - *-------------------*
- | | |
- q | | |
- | | | y = line
- V | o | x = sample
- | (y,x) |
- | |
- *-------------------*
- image(1,0) image(1,1)
-
- If point "o" falls on upper left corner, then
- return image(0,0). The point should never fall on
- any of the other corners because the calling
- program will ensure against this according to the
- filling sequence of the array image[2][2].
-
- ******************************************************
- #include <stdio.h>
-
- double nearest(image, x, y)
- float image[2][2], x, y;
- {
- register i;
- float p, q;
-
- p = x - (int) x;
- q = y - (int) y;
-
- if( (p == 0.0) && (q == 0.0) )
- return( (double) image[0][0] ); /* upper left */
-
- return( image[ (int) (q+0.5) ][ (int) (p+0.5) ] );
- }
-